package 洗牌算法;/*
 *@ 代阳敲的专属代码
 **/

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Game {
    private static final String SUIT[]={"♠","♥","♦","♣"};

    public  List<Card> createCards() {
        List<Card> cards = new ArrayList<>();
        for(int i=0;i<SUIT.length;i++) {
            for (int j=1;j<=13;j++) {
                cards.add(new Card(j,SUIT[i]));
            }
        }
        return cards;
    }
    public void shuffle(List<Card> cards) {
        Random  random = new Random();
        for(int i=cards.size()-1;i>0;i--) {
            int j =random.nextInt(i+1);
            swqp(cards,i,j);
        }
    }

    private void swqp(List<Card> cards, int i, int j) {
        Card temp=cards.get(i);
        cards.set(i,cards.get(j));
        cards.set(j,temp);
    }
    public  List<List<Card>> palyGame(List<Card> cards) {
        List<List<Card>> hands=new ArrayList<>();
        List<Card> hand1=new ArrayList<>();
        List<Card> hand2=new ArrayList<>();
        List<Card> hand3=new ArrayList<>();

        hands.add(hand1);
        hands.add(hand2);
        hands.add(hand3);

        for (int i=0;i<5;i++) {
            for(int j=0;j<hands.size();j++) {
                hands.get(j).add(cards.remove(0));
            }
        }
        return hands;
    }
}
